/**
 * <copyright>
 * </copyright>
 *

 */
package ms.unicorn.language.languagedef.impl;

import java.util.Collection;

import ms.unicorn.language.languagedef.ElementDef;
import ms.unicorn.language.languagedef.LanguagedefPackage;
import ms.unicorn.language.languagedef.RelationConstraint;
import ms.unicorn.language.languagedef.XReferenceExpression;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Relation Constraint</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link ms.unicorn.language.languagedef.impl.RelationConstraintImpl#isForbidden <em>Forbidden</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.RelationConstraintImpl#getSources <em>Sources</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.RelationConstraintImpl#getTargets <em>Targets</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.RelationConstraintImpl#getStyle <em>Style</em>}</li>
 *   <li>{@link ms.unicorn.language.languagedef.impl.RelationConstraintImpl#getValidators <em>Validators</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RelationConstraintImpl extends MinimalEObjectImpl.Container implements RelationConstraint
{
  /**
   * The default value of the '{@link #isForbidden() <em>Forbidden</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isForbidden()
   * @generated
   * @ordered
   */
  protected static final boolean FORBIDDEN_EDEFAULT = false;

  /**
   * The cached value of the '{@link #isForbidden() <em>Forbidden</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #isForbidden()
   * @generated
   * @ordered
   */
  protected boolean forbidden = FORBIDDEN_EDEFAULT;

  /**
   * The cached value of the '{@link #getSources() <em>Sources</em>}' reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getSources()
   * @generated
   * @ordered
   */
  protected EList<ElementDef> sources;

  /**
   * The cached value of the '{@link #getTargets() <em>Targets</em>}' reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getTargets()
   * @generated
   * @ordered
   */
  protected EList<ElementDef> targets;

  /**
   * The cached value of the '{@link #getStyle() <em>Style</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getStyle()
   * @generated
   * @ordered
   */
  protected XReferenceExpression style;

  /**
   * The cached value of the '{@link #getValidators() <em>Validators</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getValidators()
   * @generated
   * @ordered
   */
  protected EList<XReferenceExpression> validators;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected RelationConstraintImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return LanguagedefPackage.Literals.RELATION_CONSTRAINT;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean isForbidden()
  {
    return forbidden;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setForbidden(boolean newForbidden)
  {
    boolean oldForbidden = forbidden;
    forbidden = newForbidden;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.RELATION_CONSTRAINT__FORBIDDEN, oldForbidden, forbidden));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<ElementDef> getSources()
  {
    if (sources == null)
    {
      sources = new EObjectResolvingEList<ElementDef>(ElementDef.class, this, LanguagedefPackage.RELATION_CONSTRAINT__SOURCES);
    }
    return sources;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<ElementDef> getTargets()
  {
    if (targets == null)
    {
      targets = new EObjectResolvingEList<ElementDef>(ElementDef.class, this, LanguagedefPackage.RELATION_CONSTRAINT__TARGETS);
    }
    return targets;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public XReferenceExpression getStyle()
  {
    return style;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetStyle(XReferenceExpression newStyle, NotificationChain msgs)
  {
    XReferenceExpression oldStyle = style;
    style = newStyle;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, LanguagedefPackage.RELATION_CONSTRAINT__STYLE, oldStyle, newStyle);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setStyle(XReferenceExpression newStyle)
  {
    if (newStyle != style)
    {
      NotificationChain msgs = null;
      if (style != null)
        msgs = ((InternalEObject)style).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - LanguagedefPackage.RELATION_CONSTRAINT__STYLE, null, msgs);
      if (newStyle != null)
        msgs = ((InternalEObject)newStyle).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - LanguagedefPackage.RELATION_CONSTRAINT__STYLE, null, msgs);
      msgs = basicSetStyle(newStyle, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, LanguagedefPackage.RELATION_CONSTRAINT__STYLE, newStyle, newStyle));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<XReferenceExpression> getValidators()
  {
    if (validators == null)
    {
      validators = new EObjectContainmentEList<XReferenceExpression>(XReferenceExpression.class, this, LanguagedefPackage.RELATION_CONSTRAINT__VALIDATORS);
    }
    return validators;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case LanguagedefPackage.RELATION_CONSTRAINT__STYLE:
        return basicSetStyle(null, msgs);
      case LanguagedefPackage.RELATION_CONSTRAINT__VALIDATORS:
        return ((InternalEList<?>)getValidators()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case LanguagedefPackage.RELATION_CONSTRAINT__FORBIDDEN:
        return isForbidden();
      case LanguagedefPackage.RELATION_CONSTRAINT__SOURCES:
        return getSources();
      case LanguagedefPackage.RELATION_CONSTRAINT__TARGETS:
        return getTargets();
      case LanguagedefPackage.RELATION_CONSTRAINT__STYLE:
        return getStyle();
      case LanguagedefPackage.RELATION_CONSTRAINT__VALIDATORS:
        return getValidators();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case LanguagedefPackage.RELATION_CONSTRAINT__FORBIDDEN:
        setForbidden((Boolean)newValue);
        return;
      case LanguagedefPackage.RELATION_CONSTRAINT__SOURCES:
        getSources().clear();
        getSources().addAll((Collection<? extends ElementDef>)newValue);
        return;
      case LanguagedefPackage.RELATION_CONSTRAINT__TARGETS:
        getTargets().clear();
        getTargets().addAll((Collection<? extends ElementDef>)newValue);
        return;
      case LanguagedefPackage.RELATION_CONSTRAINT__STYLE:
        setStyle((XReferenceExpression)newValue);
        return;
      case LanguagedefPackage.RELATION_CONSTRAINT__VALIDATORS:
        getValidators().clear();
        getValidators().addAll((Collection<? extends XReferenceExpression>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case LanguagedefPackage.RELATION_CONSTRAINT__FORBIDDEN:
        setForbidden(FORBIDDEN_EDEFAULT);
        return;
      case LanguagedefPackage.RELATION_CONSTRAINT__SOURCES:
        getSources().clear();
        return;
      case LanguagedefPackage.RELATION_CONSTRAINT__TARGETS:
        getTargets().clear();
        return;
      case LanguagedefPackage.RELATION_CONSTRAINT__STYLE:
        setStyle((XReferenceExpression)null);
        return;
      case LanguagedefPackage.RELATION_CONSTRAINT__VALIDATORS:
        getValidators().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case LanguagedefPackage.RELATION_CONSTRAINT__FORBIDDEN:
        return forbidden != FORBIDDEN_EDEFAULT;
      case LanguagedefPackage.RELATION_CONSTRAINT__SOURCES:
        return sources != null && !sources.isEmpty();
      case LanguagedefPackage.RELATION_CONSTRAINT__TARGETS:
        return targets != null && !targets.isEmpty();
      case LanguagedefPackage.RELATION_CONSTRAINT__STYLE:
        return style != null;
      case LanguagedefPackage.RELATION_CONSTRAINT__VALIDATORS:
        return validators != null && !validators.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (forbidden: ");
    result.append(forbidden);
    result.append(')');
    return result.toString();
  }

} //RelationConstraintImpl
